<template>
  <view>
    <view class="remark-view content-box ">
      <view style="" class="popup-title">
        免单确认
      </view>

      <view class="title-row">
        免单原因 <text class="red">*</text>
      </view>

      <view class="button-content" v-if="list.length > 0">
        <view @click="clickDisaccountTag(item)" v-for="(item) in list" class="bottom-button"
          :class="{isActive:disaccountTag && disaccountTag.reason_no&& item.reason_no === disaccountTag.reason_no}">
          {{item.discount_reason}}
        </view>
        <view class="bottom-button" :class="{isActive:disaccountTag==='自定义'}" @click="clickDisaccountTag('自定义')">
          自定义
        </view>
      </view>

      <u-textarea :customStyle="{fontSize:'4rem',margin:'0 2rem'}" v-model="customConfig" placeholder="请输入免单原因" count
        v-if="disaccountTag==='自定义'"></u-textarea>

      <view style="padding: 1.3rem;" class="button-bottom-row">
        <button class="button lg line-white" @click="cancle">取消</button>
        <button class="button lg" @click="submit">免单并结算</button>
      </view>

    </view>
  </view>
</template>

<script>
  export default {
    props: {
      noPayAmount: {
        type: [Number, String]
      },
      billData: {
        type: Object
      },
    },
    data() {
      return {
        isDetail: false,
        disaccountTag: false,
        disaccountNumber: '100',
        customConfig: '',
        list: [],

      }
    },
    methods: {
      clickDisaccountTag(item) {
        this.disaccountTag = item;
      },
      cancle() {
        this.$emit("cancle", "freeOrder");
      },
      submit() {
        if (this.disaccountTag === false) {
          uni.showToast({
            title: '请选择免单原因',
            icon: 'none'
          })
          return
        }
        if (this.disaccountTag === '自定义' && !this.customConfig) {
          uni.showToast({
            title: '请输入免单原因',
            icon: 'none'
          })
          return
        }
        let data = {
          discount_reason: '',
          remark: '',
          discount_reason_name: this.disaccountTag?.discount_reason || this.customConfig
        }
        if (this.disaccountTag) {
          data.discount_reason = this.disaccountTag.reason_no;
          data.remark = this.disaccountTag?.discount_reason || this.customConfig;
        }
        console.log(data, "data是什么？？？？？？")
        this.$emit("confirmFreeOrder", data)
      },
      getTime(date) {
        let filterDate = function(date) {
          if (date < 10) {
            return `0${date}`
          } else {
            return date;
          }
        }
        // console.log("我被打印了---");
        let year = date.getFullYear();
        let month = filterDate(date.getMonth());
        let dates = filterDate(date.getDate());
        let Hour = filterDate(date.getHours());
        let minutes = filterDate(date.getMinutes());
        let seconds = filterDate(date.getSeconds());

        return `${year}-${month}-${dates} ${Hour}:${minutes}:${seconds}`;
      },

      getList() {
        const url = `/retail/select/srvretail_discount_reason_select`;

        const req = {
          "serviceName": "srvretail_discount_reason_select",
          "colNames": ["*"],
          "condition": [],

          // "page": {
          // 	"pageNo": 1,
          // 	"rownumber": 10
          // },
          "order": [],
          "draft": false,

        }


        this.$http.post(url, req).then(res => {
          if (res?.data?.state === 'SUCCESS') {
            console.log(res, "res--res--")
            this.list = res.data.data;
            // res.data.data.forEach((item)=>{
            //   if(item.online_state == '离线'){
            // 		 item.shouldIcon="bluePrint";
            // 	}else if(item.online_state == '在线'){
            // 		item.shouldIcon="smallSizeGreen";
            // 	}else if(item.online_state == '在线异常'){
            // 			item.shouldIcon="red";
            // 	}
            // })
            // this.list = res.data.data;
          }

          uni.hideLoading()
        }).catch(_ => {
          uni.hideLoading()
        })
      }

    },
    created() {
      this.getList()
    },
    onLoad() {



    }

  }
</script>

<style lang="scss" scoped>
  .number-type {
    border: 1px solid #38C09E;
    border-radius: 1rem;
    flex: 1;
    height: 20px;
    margin-right: 3rem;
    padding: 0 2.4rem;
    font-size: 2.4rem;
  }

  .content-box {
    padding: 0 0 2rem;
    width: 50vw;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
  }

  .button-bottom-row {
    display: flex;
    width: 100%;
    justify-content: center;
    margin-top: 2rem;
    flex: 1;
    align-items: flex-end;
    padding: 2rem;

    .button {
      min-width: 30rem;
      margin-right: 2rem;
    }
  }

  .noMargin {
    margin-right: 0px !important;
  }

  .noMarginBottom {
    margin-bottom: 0px !important;

  }

  .green {
    background: rgba(56, 192, 158, 1);
    color: white;
  }

  .fake-button {
    display: flex;

    justify-content: space-between;

    align-items: center;
    border-radius: 3px;
    margin-right: 1rem;
    margin-bottom: 1rem;
    // width: 12.75rem;
    height: 4rem;
    justify-content: center;
    background: rgba(255, 255, 255, 1);
    border: 1px solid rgba(229, 229, 229, 1);
  }

  .bottom-button {
    border-radius: .5rem;
    margin-right: 1rem;
    padding: 1rem 2rem;
    font-size: 2.4rem;

    background: #fff;
    border: 1px solid #e5e5e5;

    &:hover {

      background: rgba(222, 242, 234, 1);

      border: 1px solid rgba(56, 192, 158, 1);
    }

    &.isActive {
      color: #38C09E;
      background: rgba(222, 242, 234, 1);

      border: 1px solid rgba(56, 192, 158, 1);
    }
  }



  .fake-button {
    cursor: pointer;

    &:hover {

      background: rgba(222, 242, 234, 1);

      border: 1px solid rgba(56, 192, 158, 1);


    }
  }

  .fake-button-top {
    display: inline-flex;
    align-items: center;
    border-radius: 0.6rem;
    font-size: 1.4rem;
    align-items: center;
    padding: .5rem 1.5rem;
    cursor: pointer;
    border-radius: .5rem;
    justify-content: center;

    &.first {
      margin-right: 1rem;
    }


  }

  .pop-content {
    box-sizing: border-box;
    min-width: 60rem;
    padding: 1.5rem 3rem;
  }

  .submit-button {
    border-radius: 4px;
    background: #38c09e;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;

    align-items: center;
    justify-content: center;
    color: white;
    height: 31px;
    font-size: 16px;
    align-items: center;
    cursor: pointer;
  }

  .delete-button {
    display: flex;
    justify-content: space-between;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #e5e5e5;
    align-items: center;
    cursor: pointer;

  }


  .title-row {
    padding: 0 2rem;
    font-size: 2.4rem;
    font-weight: 800;
    color: rgba(128, 128, 128, 1);
    margin-bottom: 2rem;

  }


  .bottom-content {
    display: flex;
    flex-wrap: wrap;




    .button-row {
      width: 100%;
      border-radius: 0.5rem;
      border: 1px solid #38c09e;
      padding: 1.1rem 1.1em;
      display: flex;
      flex: 1;
      justify-content: space-between;

    }

    .right {
      display: flex;
      font-size: 2rem;
      align-items: center;

    }
  }

  .button-content {
    display: flex;
    width: 100%;
    margin-bottom: 2rem;
    padding: 0 2rem;
  }


  .button-content-cal {
    display: flex;
    width: 100%;

    .button-row {
      display: flex;
      flex-direction: column;
      flex: 1;
    }

  }

  .disaccountText {
    margin-bottom: 15px;
    color: #a6a6a6;
    margin-top: 9px;
  }

  .red {
    color: rgba(255, 87, 51, 1);
  }
</style>
